//
//  UICollectionView+Extension.swift
//  Library_y
//
//  Created by JC on 2023/6/6.
//

import Foundation
import UIKit

public extension UICollectionView {
    
    /// 复用队列
    func dequeueReusableCell<T: UICollectionViewCell>(type: T.Type, for indexPath: IndexPath) -> T {
        return dequeueReusableCell(withReuseIdentifier: "\(type.self)", for: indexPath) as! T
    }
    
    /// 注册带xib的cell
    ///
    /// - Parameters:
    ///   - type: cell类名
    ///   - identifier: 复用id
    func registerNibName<T: UICollectionViewCell>(type: T.Type, identifier: String = "\(T.self)") {
        register(UINib.init(nibName: "\(type.self)", bundle: nil), forCellWithReuseIdentifier: identifier)
    }
}

public extension UICollectionView {
    
    func reloadData(complete: @escaping () -> Void) {
        
        DispatchQueue.main.async { [weak self] in
            self?.reloadData()
            DispatchQueue.main.async {
                complete()
            }
        }
    }
}
